package net.fireox.oa.sys.security.service.impl;

import javax.annotation.Resource;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Component
@Repository(value="sysBaseSecurityRealm")
public class BaseSecurityRealm extends AuthorizingRealm 
{

	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(
			PrincipalCollection principals) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@Transactional
	protected AuthenticationInfo doGetAuthenticationInfo(
			AuthenticationToken authenticationToken) throws AuthenticationException {
		// TODO Auto-generated method stub
		UsernamePasswordToken token = (UsernamePasswordToken)authenticationToken;
		
		String username = token.getUsername();
		
		//User user = userDao.selectOne("SELECT obj FROM User AS obj WHERE obj.username='" + username.trim().toLowerCase() + "'");
		/*Object user = null;
		if(user==null)
		{
			throw new UnknownAccountException();
		}
		else if(user.getLocked()!=null&&user.getLocked())
		{
			throw new LockedAccountException();
		}
		else
		{
			
		}*/
		
		SimpleAuthenticationInfo info = new SimpleAuthenticationInfo("admin", "admin", getName());
		
		return info;
	}
}
